# coding:utf8
"""
From https://pypi.org/project/elasticsearch/
"""
from datetime import datetime
from elasticsearch2 import Elasticsearch

# by default we connect to localhost:9200
es = Elasticsearch()


def init():
    # create an index in elasticsearch, ignore status code 400 (index already exists)
    es.indices.create(index='my-index', ignore=400)

    # datetimes will be serialized
    es.index(index="my-index", doc_type="test-type", id=42, body={
        "any": "data",
        "timestamp": datetime.now()
    })


def func01():
    # but not deserialized
    _source = es.get(index="my-index", doc_type="test-type", id=42)['_source']
    print(_source)


if __name__ == "__main__":
    func01()




